package com.bit.book.model;

import com.bit.book.enums.CodeStatus;
import lombok.Data;

@Data
public class Result<T> {
    //业务状态码
    //自己定义
    //200正常  -1 未登录  -2 异常 ...
    private CodeStatus code;

    private String errorMsg;
    private T data;

    public static <T> Result<T> success(T data){
        Result result = new Result();
        result.setCode(CodeStatus.SUCCESS);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> fail(String errMsg){
        Result result = new Result();
        result.setCode(CodeStatus.ERROR);
        result.setErrorMsg(errMsg);
        return result;
    }

    public static Result unLogin(){
        Result result = new Result();
        result.setCode(CodeStatus.UNLOGIN);
        result.setErrorMsg("用户未登录");
        return result;
    }

    public static <T> Result<T> unLogin(T data){
        Result result = new Result();
        result.setCode(CodeStatus.UNLOGIN);
        result.setErrorMsg("用户未登录");
        result.setData(data);
        return result;
    }
}
